package com.example.demo.mapper.log;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.PageRes;
import com.example.demo.bean.log.SysLoginLogDO;
import com.example.demo.dto.log.SysLoginLogPageReqVO;
import com.example.demo.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SysLoginLogMapper extends BaseMapperX<SysLoginLogDO> {

    default PageRes<SysLoginLogDO> selectPage(SysLoginLogPageReqVO reqVO){
        Page<SysLoginLogDO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        return selectPageCommon(page,new QueryWrapper<SysLoginLogDO>()
                .like(ObjectUtil.isNotNull(reqVO.getLoginLocation()),"login_location",reqVO.getLoginLocation())
                .like(ObjectUtil.isNotNull(reqVO.getUserName()),"user_name",reqVO.getUserName())
                .eq(ObjectUtil.isNotNull(reqVO.getStatus()),"status",reqVO.getStatus())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "login_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
        );
    }
}
